import numpy as na


class Segment(object):
    def __init__(self):
        
        self.SegmentPaths=[]#List of paths generated from getThinningModel.py
        self.selectedPoint=[] #[i,j,k] value, critical point
        self.centerLine=[] #numpy array of points along a particular segment, individual arrays within the list of segmentPaths
        self.minpointDistance=100 #for each segment, report the minimum distance to the point.
        self.SegLength=0 #for each segment report the number of points within the path
        self.edgeDist=0 #Reports the distance between the centerline and the vessel edge for a segment
        self.pointEdgeDist=0 #Reports the distance from the point to the vessel edge
        self.segment=[]
        self.leftroot=[] #passed in from dataset
        self.rightroot=[] 
        self.endpoint=[]
    def HighlLightFxn(self):
        """Used to show the nearest segement in the viewer"""
        
    def DistanceFromSelectedPoint(self, CritPoint, Paths):
        """Used to calculate the distances from the selected point to each of the centerlines for each segment using min distance"""
        self.selectedPoint=CritPoint
        self.SegmentPaths=Paths
        Distance=[]
        for segment in self.SegmentPaths:
            for clPoint in segment:
                distance=na.min(clPoint-self.selectedPoint)
                if distance<self.minpointDistance:
                    self.minpointDistance=distance
                    nearestStructure=HighlightFxn(segment)
                else:
                    Distances.append(distance)
        
    def DistanceFromSelectedPoint2(self, CritPoint):
        """Used to calculate the distances from the selected point to each of the centerlines for each segment using sqrt distance"""
        self.selectedPoint=CritPoint
        self.SegmentPaths=Paths
        Distance=[]
        for self.segment in self.SegmentPaths:
            for clPoint in self.segment:
                distance=na.sqrt{[clPoint-self.selectedPoint])#Need to fix
                if distance<self.minpointDistance:
                    self.minpointDistance=distance
                    nearestStructure=HighlightFxn(self.segment)
                else:
                    Distances.append(distance)        
        
    def CalculateSegmentStatistics(self):
        """Understanding the nearest structure"""
        self.SegLength=len(self.segment)
        print "There are", self.SegLength,"points in the nearest segment"
        #Does the segment contain the root? The endpoint? How many segments back to the root?
        
        
    